#ifndef __MutexLock_H__
#define __MutexLock_H__

#include "Noncopyable.h"

#include <pthread.h>

namespace wd
{

class MutexLock : Noncopyable
{
public:
    MutexLock();
    ~MutexLock();

    //是inline函数吗？
    void lock();
    void unlock();

    //在类内部实现的函数都是inline函数
    pthread_mutex_t * getMutexLockPtr() {   return &_mutex; }

private:
    pthread_mutex_t _mutex;
};

class MutexLockGuard
{
public:
    MutexLockGuard(MutexLock & m)
    : _mutex(m)
    {
        _mutex.lock();
    }

    ~MutexLockGuard()
    {
        _mutex.unlock();
    }

private:
    MutexLock & _mutex;
};


#if 0
//不是inline函数
void MutexLock::lock()
{
    pthread_mutex_lock(&_mutex);
}
#endif



}//end of namespace wd


#endif

